//
//  LotteryOpenViewDetailController.m
//  PlayBall
//
//  Created by 龙华 伍 on 12-7-1.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JddLotteryOpenViewDetailController.h"
#import "SBJson.h"

@implementation JddLotteryOpenViewDetailController

@synthesize LotNameLabel;
@synthesize IssueLabel;
@synthesize OpenDateLabel;
@synthesize GetEndDateLabel;
@synthesize lotName;
@synthesize SalesLabel;
@synthesize idMoney1Label;//中奖金额总和
@synthesize JackpotLabel;
@synthesize JackpotLabel2;
@synthesize listTable;
@synthesize jx;
@synthesize zjzs;
@synthesize everyMoney;
@synthesize realResult;
@synthesize resultArray;
@synthesize lab1;
@synthesize lab2;
@synthesize lab3;
@synthesize lab4;
@synthesize lab5;

SHARED_VIEW_CONTROLLER_IMPLEMENT(JddLotteryOpenViewDetailController);

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
   
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    customLab.backgroundColor = [UIColor clearColor];
    [customLab setText:PAGE_OPEN_DETAIL];
    customLab.textAlignment = NSTextAlignmentCenter;

    [customLab setTextColor:[UIColor whiteColor]];
    customLab.font = [UIFont systemFontOfSize:19];
    self.navigationItem.titleView = customLab;
    
//    //self.navigationItem.hidesBackButton = YES;
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,0)];
    listTable.tableFooterView = v;
    [self.listTable setSeparatorColor:SeparatorLineColor];
    if (IOS7) {
        [self.listTable setSeparatorInset:UIEdgeInsetsZero];
    }
    lab1.layer.borderWidth = 0.5;
    lab1.layer.borderColor = BORDER_COLOR;
    lab2.layer.borderWidth = 0.5;
    lab2.layer.borderColor = BORDER_COLOR;
    lab3.layer.borderWidth = 0.5;
    lab3.layer.borderColor = BORDER_COLOR;
    lab4.layer.borderWidth = 0.5;
    lab4.layer.borderColor = BORDER_COLOR;
    lab5.layer.borderWidth = 0.5;
    lab5.layer.borderColor = BORDER_COLOR;
    idMoney1Label.layer.borderWidth = 0.5;
    idMoney1Label.layer.borderColor = BORDER_COLOR;
    SalesLabel.layer.borderWidth = 0.5;
    SalesLabel.layer.borderColor = BORDER_COLOR;

}


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete;
}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return DELETE;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [resultArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 24.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    JddLotteryOpenItemDetailTabelCell *cell = [JddLotteryOpenItemDetailTabelCell getInstanceView];
    NSDictionary *cellvalue = [resultArray objectAtIndex:indexPath.row];
    cell.salesLabel.text = [cellvalue objectForKey:@"Name"];

    cell.WinNumberLabel.text = [NSString stringWithFormat:@"%@", [cellvalue objectForKey:@"Count"]];
    cell.MoneyLabel.text = [cellvalue objectForKey:@"Money"];
    cell.delegate = self;
    return cell;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"LotteryInfo-digitalDetail"];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"LotteryInfo-digitalDetail"];

    SBJsonParser *jsonparser = [[SBJsonParser alloc] init];
    NSDictionary *buydetail = [jsonparser objectWithString:realResult];
    //    self.JackpotLabel.text = [buydetail objectForKey:@"WinNumber"];
    NSString *string3 = [buydetail objectForKey:@"Number"];
    NSArray *array2 = [string3 componentsSeparatedByString:@"+"];
    NSMutableString *string4 = [array2 objectAtIndex:0];
    
    if ([array2 count]>1) {
        self.JackpotLabel.text = [NSString stringWithFormat:@"%@+",string4];
        self.JackpotLabel2.text = [array2 objectAtIndex:1];
    }else {
        self.JackpotLabel.text = [NSString stringWithFormat:@"%@",string4];
        self.JackpotLabel2.text = @"";
    }
    
//    NSString *winNum = [buydetail objectForKey:@"WinNumber"];
//    NSString *winNum2 = [winNum stringByReplacingOccurrencesOfString:@"+" withString:@" "];
//    NSArray *winnumArray = [winNum2 componentsSeparatedByString:@" "];
    self.IssueLabel.text = jx;
    self.OpenDateLabel.text = [JddCommonFunction getStringDateWithStringDateTime:[buydetail objectForKey:@"EndTime"]];
    self.GetEndDateLabel.text = [JddCommonFunction getOpenEndDateWithEndtime:[buydetail objectForKey:@"EndTime"]];
    self.LotNameLabel.text = [buydetail objectForKey:@"LottName"];
    lotName = [buydetail objectForKey:@"LottName"];
    
    self.idMoney1Label.text =[NSString stringWithFormat:@"%@", [buydetail objectForKey:@"Sales"]];
    self.SalesLabel.text = [NSString stringWithFormat:@"%@", [buydetail objectForKey:@"Balance"]];
    if ([[buydetail objectForKey:@"Balance"] intValue] == 0) {
        self.SalesLabel.hidden = YES;
        lab5.hidden = YES;
        CGRect frame = self.idMoney1Label.frame;
        frame.size.width = 290;
        self.idMoney1Label.frame = frame;
        
        frame.origin.y = lab4.frame.origin.y;
        lab4.frame = frame;
    } else {
        self.SalesLabel.hidden = NO;
        lab5.hidden = NO;
        CGRect frame = self.idMoney1Label.frame;
        frame.size.width = 145;
        self.idMoney1Label.frame = frame;
        
        frame.origin.y = lab4.frame.origin.y;
        lab4.frame = frame;
    }
    resultArray = [buydetail objectForKey:@"Wins"];
    if ([lotName isEqualToString:@"福彩3D"]||[lotName isEqualToString:@"排列3"]||[lotName isEqualToString:@"排列5"]) {
        self.SalesLabel.text = @"该彩种不支持奖池";
    }
    [listTable reloadData]; 
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

